﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ComLib.ConfigService;
using ComLib.ComFun;
using ComLib.ComType;

namespace ProcessConfig.ConfigType
{
    [XmlRootAttribute("PhotoTakenOption", Namespace = "ProcessConfig.ConfigType", IsNullable = false)]
    public class PhotoTakenOption : XmlSerializeBase
    {      
        /// <summary>
        /// 拍照业务类型
        /// </summary>
        private ServiceTypes _serType = ServiceTypes.ExitAndEntry;
        public ServiceTypes ServiceType
        {
            get { return _serType; }
            set { _serType = value; }
        }

        /// <summary>
        /// 拍照张数
        /// </summary>
        private int _takingCount = 2;
        public int TakingCount
        {
            get { return _takingCount; }
            set { _takingCount = value; }
        }

        public override bool Serialize()
        {
            return Serializer.SaveToXml(ConfigFilePath, this);
        }

        public override bool Load()
        {
            PhotoTakenOption obj = (PhotoTakenOption)Serializer.LoadFromXml(ConfigFilePath, this.GetType());
            if (obj != null)
            {
                this._nVer = obj._nVer;
                this._serType = obj._serType;
                this._takingCount = obj._takingCount;
                return true;
            }
            else
            {
                ErrorMessage = Serializer.Message;
                return false;
            }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("拍照选项: ");
            FillFieldValueStringDelegate FillString =
                (string field, object val) =>
                {
                    if (val != null)
                    {
                        builder.Append("[");
                        builder.Append(field);
                        builder.Append("]: ");
                        builder.Append(val.ToString() + "; ");
                    }
                };
            FillString("照片业务类型", _serType);       
            FillString("拍照张数", _takingCount);          
            return builder.ToString();
        }
    }
}
